import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel
from PyQt5.QtGui import QColor


class ExampleHide(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Example Hide")
        self.setGeometry(100, 100, 300, 200)

        # 创建一个垂直布局
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        # 创建一个标签 -- 可以隐藏
        self.label = QLabel("Hello, PyQt5!", self)

        # 创建一个按钮
        self.btn_hide_label = QPushButton("label hide", self)
        self.btn_hide_label.clicked.connect(self.signal_btn_hide_lable)
        self.btn_hide_label_status = False

        # 添加到布局
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.btn_hide_label)

    def signal_btn_hide_lable(self):
        if self.btn_hide_label_status:
            self.btn_hide_label.setText("label hide")
            self.label.setVisible(True)
            self.btn_hide_label_status = False
        else:
            self.btn_hide_label.setText("label show")
            self.label.setVisible(False)
            self.btn_hide_label_status = True

if __name__ == "__main__":
    app = QApplication(sys.argv)
    ui = ExampleHide()
    ui.show()
    sys.exit(app.exec_())